% clc
% clear

var_name  = 'zs';
LevelStep = 200;

plt_res   = 0.1;
FontSize  = 6;
hr        = 0;

ncfile = '../run/hope_output.n90.nc';
% ncfile = '../run/hope_output.n45_10min.nc';

lon = ncread(ncfile,'lon');
lat = ncread(ncfile,'lat');
var = ncread(ncfile,var_name);

% lon_min = 0;
% lon_max = 360;
% lat_min = -90;
% lat_max = 90;
lon_min = 70;
lon_max = 115;
lat_min = 20;
lat_max = 55;

nx = size(lon,1);
ny = size(lon,1);
np = size(lon,3);

nz = size(var,4);
nt = size(var,1);

var_p = var; % variable on pressure level

lon1d = reshape(lon,[],1);
lat1d = reshape(lat,[],1);

lon_plt = lon_min:plt_res:lon_max;
lat_plt = lat_min:plt_res:lat_max;
[lon_plt,lat_plt] = meshgrid(lon_plt,lat_plt);

var1d = reshape(var_p,[],1);

% extend for interpolation
n1d = size(lon1d,1);
lon1d_ext(0*n1d+1:1*n1d) = lon1d - 360;
lon1d_ext(1*n1d+1:2*n1d) = lon1d;
lon1d_ext(2*n1d+1:3*n1d) = lon1d + 360;
lat1d_ext(0*n1d+1:1*n1d) = lat1d;
lat1d_ext(1*n1d+1:2*n1d) = lat1d;
lat1d_ext(2*n1d+1:3*n1d) = lat1d;
var1d_ext(0*n1d+1:1*n1d) = var1d;
var1d_ext(1*n1d+1:2*n1d) = var1d;
var1d_ext(2*n1d+1:3*n1d) = var1d;

var_plt = griddata(lon1d_ext,lat1d_ext,var1d_ext,lon_plt,lat_plt,'linear');
% var_plt = griddata(lon1d_ext,lat1d_ext,var1d_ext,lon_plt,lat_plt,'cubic');

figure
% % pcolor plot
% plt = pcolor(lon_plt,lat_plt,squeeze(var_plt));
% set(plt,'EdgeColor','None')
% % shading interp
% set(gca,'Clim',[cmin,cmax])
% colormap(jet)
% colorbar

% contour plot
[plt,h]=contour(lon_plt,lat_plt,squeeze(var_plt),'LevelStep',LevelStep,'ShowText','on');
% set(gca,'Clim',[cmin,cmax])
clabel(plt,h,'FontSize',FontSize)
colormap(jet)

title(['HOPE ',var_name])
varname_file = strrep(var_name,'\','');
print(gcf,'-r600','-dpng',['HOPE_',varname_file,'.png']);